//订单管理-商城订单列表
App.util.ns('Admin.Orders.Shopping');
App.pages.add((function(){
    var NS = Admin.Orders.Shopping;
    var page = new App.Page({
        name: 'orders/shopping/index'
    });
    //页面初始化
    page.initStack.add('dataTable', function(){
        //面包屑导航
        this.setBreadcrumb([{
            icon: '<i class="fa fa-dollar"></i>',
            content: '订单管理'
        }, {
            content: '商城订单'
        }]);
        this.dataTable = new App.DataTable({
            baseUrl: '/admin/orders/shopping',
            dataUrl: 'lists',
            table: {
                id: 'id',
                main: 0,
                //showId: false,
                columns: App.util.copy(NS.Conf.columns)
            },
            filter: [
                {type: 'timeRange'},
                {type: 'select', name: 'status', title: '订单状态', width: '80px', items: [
                    [1, '待支付'],
                    [2, '支付完成'],
                    [3, '订单完成'],
                    [4, '失败']
                ]},
                // {type: 'select', name: 'supplier_id', title: '供应商', width: '120px',
                //     items: App.models.get('supplier-all'),
                //     item_key: 'id',
                //     item_name: 'name'
                // }
            ],
            menu: [
                {
                    type: 'inline',
                    name: '运单填写',
                    icon: '<i class="fa fa-server"></i>',
                    floatable: true,
                    permission: 'gp:admin/orders/shopping',
                    conditions: [['type', '4'],['status', '2']],
                    operation: function(dataTable, orders){
                        var win = dataTable.wins.get('deliversno');
                        win.form.change({
                            order_id: orders.id,
                            user_id: orders.user_id,
                        });
                        win.show();
                    }
                },
                {type: 'globe', name: '导出', permission: 'op:admin.orders.shopping.multiExport', operation:function (dataTable) {
                    //发请求ajax
                    $.ajax({
                        url: 'admin/orders/shopping/multiExport',
                        data: dataTable.filter.data,
                        type: "get",
                        async: false,
                        success: function (returnData) {
                            returnData = JSON.parse(returnData)
                            if(returnData.status == '0'){
                                var $a = $("<a>");
                                $a.attr("href", returnData.data.file);
                                $a.attr("download", returnData.data.filename);
                                $("body").append($a);
                                $a[0].click();
                                $a.remove();
                            }else {
                                App.util.hint.toast({
                                    type: 'error',
                                    text: returnData.msg
                                }).delay(500);
                            }
                        },
                        error: function () {
                            App.util.hint.toast({
                                type: 'error',
                                text: '格式不对'
                            }).delay(500);
                        }
                    });

                }},
                {parent: 'multiDrop', permission: 'op:admin.orders.shopping.multiDelete'},
            ],
            detail: {
                form: {
                    items: App.util.copy(NS.Conf.form)
                }
            },
            after: function(dataTable){
                dataTable.wins.add(new NS.Deliversno(dataTable), 'deliversno');
            }
        }, page);
        this.dataTable.fix(this.contentContainer);
        this.dataTable.loadData();
    });
    //页面刷新
    page.refreshStack.add('dataTable', function(){
        this.dataTable.loadData(true);
    });
    //页面销毁
    page.destroyStack.add('dataTable', function(){
        this.dataTable.destroy();
    });
    return page;
})());